package zouran.service.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zouran.entity.User;
import zouran.mapper.UserMapper;
import zouran.service.UserService;

import java.util.Objects;
/**
 * @Author: zouran
 * @Description:
 * @Date: Created in 2022 2022/12/3 16:31
 **/
@Service
public class UserServiceImpl implements UserService {
    UserMapper userMapper;
    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }
    @Override
    public int judge_user(String Phone, String Password)
{
   if(userMapper.selectById(Phone)==null) return 0;
   else if(Objects.equals(userMapper.selectById(Phone).getUserPassword(), Password))
       return 2;
          else return 1;
}
    @Override
    public int sign(User user)
    {
        if(userMapper.selectById(user.getUserPhone())==null)
        return userMapper.insert(user) ;
        else return 0;
    }
    @Override
    public int update_myself(User user)
    {
        if(Objects.equals(userMapper.selectById(user.getUserPhone()).getUserPassword(), user.getUserPassword()))
             return userMapper.updateById(user);//返回1
        else return 0;
    }
    @Override
    public boolean logout_myself(User user){
       return userMapper.deleteById(user)==1;
    }
}
